package com.gushenge.core

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.os.Build
import android.provider.Settings
import android.text.TextUtils
import android.util.Log
import com.google.common.net.HttpHeaders
import com.gushenge.atools.ATools
import com.gushenge.core.dao.MMKVConsts
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.MaterialHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.constant.SpinnerStyle
import com.shuyu.gsyvideoplayer.player.IjkPlayerManager
import com.shuyu.gsyvideoplayer.player.PlayerFactory
import com.tencent.mmkv.MMKV
import me.jessyan.autosize.AutoSizeConfig
import okhttp3.OkHttpClient
import org.litepal.LitePal
import java.util.*
import java.util.concurrent.TimeUnit
import java.util.logging.Level


/**
 * Created by Administrator on 2017/8/9 0009.
 */

open class CoreApplication : Application() {
    @SuppressLint("CommitPrefEdits")
    override fun onCreate() {
        super.onCreate()
        instance = this
        val rootDir = MMKV.initialize(this)
        Log.d("test", "rootDir:$rootDir")
    }

    companion object {
        //static 代码段可以防止内存泄露
        init {
            //设置全局的Header构建器
            SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, _ ->
                MaterialHeader(context)
            }
            //设置全局的Footer构建器
            SmartRefreshLayout.setDefaultRefreshFooterCreator { context, _ ->
                ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate)
            }
        }
        lateinit var instance: CoreApplication
            private set
    }
}
fun getUPID(mContext: Context): String {
    if(MMKVConsts.eaua.isNullOrBlank()){
        //使用硬件信息拼凑出来的15位号码
        var m_szAndroidID: String =
            Settings.Secure.getString(mContext.contentResolver, Settings.Secure.ANDROID_ID)
        val m_szDevIDShort =
            "35" + Build.BOARD.length % 10 + Build.BRAND.length % 10 + Build.CPU_ABI.length % 10 + Build.DEVICE.length % 10 + Build.DISPLAY.length % 10 + Build.HOST.length % 10 + Build.ID.length % 10 + Build.MANUFACTURER.length % 10 + Build.MODEL.length % 10 + Build.PRODUCT.length % 10 + Build.TAGS.length % 10 + Build.TYPE.length % 10 + Build.USER.length % 10 //13 位
        if (TextUtils.isEmpty(m_szAndroidID)) {
            m_szAndroidID = "PsuedoID"
        }
        MMKVConsts.eaua=   UUID(m_szDevIDShort.hashCode().toLong(), m_szAndroidID.hashCode().toLong()).toString()
    }
    return  MMKVConsts.eaua
}